package org.example.examsystem.service;


import org.example.examsystem.entity.UnansweredExam;
import org.example.examsystem.mapper.UnansweredExamMapper;
import org.example.examsystem.service.UnansweredExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UnansweredExamServiceImpl implements UnansweredExamService {

    @Autowired
    private UnansweredExamMapper unansweredExamMapper;

    @Override
    public Page<UnansweredExam> getUnansweredExams(Pageable pageable, Integer classid) {
        int offset = pageable.getPageNumber() * pageable.getPageSize();
        int pageSize = pageable.getPageSize();
        List<UnansweredExam> exams = unansweredExamMapper.getUnansweredExams(offset, pageSize,classid);
        int total = unansweredExamMapper.countUnansweredExams(classid);
        return new PageImpl<>(exams, pageable, total);
    }
}